#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define TRUE 1
#define FALSE 0
#define OK 1 
#define ERROR 0
#define OVERFLOW -2
#define MAXSTRLEN 255
typedef int Status;
typedef unsigned char SString[MAXSTRLEN + 1];
// p73 algothrim 4.2
Status Concat(SString &T, SString S1, SString S2)
{
    bool uncut;
    if (S1[0] + S2[0] <= MAXSTRLEN)
    {
        for (int i = 1; i <= S1[0]; i++)
            T[i] = S1[i];
        for (int i = S1[0] + 1; i <= S1[0] + S2[0]; i++)
            T[i] = S2[i];
        T[0] = S1[0] + S2[0];
        uncut = TRUE;
    }
    else if (S1[0] < MAXSTRLEN)
    {
        for (int i = 1; i <= S1[0]; i++)
            T[i] = S1[i];
        for (int i = S1[0] + 1; i <= MAXSTRLEN; i++)
            T[i] = S2[i];
        T[0] = MAXSTRLEN;
        uncut = FALSE;
    }
    else
    {
        for (int i = 0; i <= MAXSTRLEN; i++)
            T[i] = S1[i];
        uncut = FALSE;
    }
    return uncut;
}
// p75 algothrim 4.3
Status SubString(SString &Sub, SString S, int pos, int len)
{
    if (pos < 1 || len < 0 || pos > S[0] || pos + len > S[0] + 1)
        return ERROR;
    for (int i = 1; i <= len; i++)
        Sub[i] = S[pos + i - 1];
    Sub[0] = len;
    return OK;
}
int main(void)
{
    return 0;
}